$(function () {
    $('#orderList').on('click', '.delete', function () {
        var _vm = $(this);
        var isSure = confirm('您确定要删除我吗？');
        if (isSure) {
            var list = _vm.parents('.menuList');
            var id = list.attr('data-id');
            var option = {
                type: 'post',
                url: 'admin/order.php',
                data: {
                    postType: 'deleteItem',
                    id: id
                }
            };
            requestEvent(option, function (res) {
                if (res.status == 1) {
                    list.remove();
                    return false;
                }
                alert(res.msg);
            })
        }
    });
    getDatas();

    function getDatas() {
        var option = {
            type: 'get',
            url: 'admin/order.php',
            data: {
                getType: 'getShopCart'
            }
        };
        requestEvent(option, function (res) {
            initHtml(res);
        })
    }

    function initHtml(data) {
        var str = '';
        if (data && data.length > 0) {
            for (var i = 0, n = data.length; i < n; i++) {
                var price = Number(data[i].price).toFixed(2);
                str += ''
                    + '<div class="menuList" data-id="' + data[i].sid + '">'
                    + '<a class="clearFix" href="#">'
                    + '<img src="' + data[i].imgSrc + '" alt="">'
                    + '<div class="menuListRight">'
                    + '<h5 class="listTitle">' + data[i].title + '</h5>'
                    + '<p class="proColor">颜色:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<span>' + data[i].scolor + '</span>)</p>'
                    + '<p class="number">数量:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X<span>' + data[i].num + '</span></p>'
                    + '<p class="price">￥<span>' + price + '</span></p>'
                    + '</div>'
                    + '</a>'
                    + '<button class="delete">删除</button>'
                    + '</div>';
            }
        }
        $('#orderList').html(str);
    }
});